package view.mediator.weapon.flute
{
	import model.item.ItemModel;
	import model.weapon.WeaponModel;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import view.component.weapon.flute.FluteDetailView;
	import view.event.ItemEvent;
	import view.event.weapon.flute.FluteDetailViewEvent;
	
	
	/**
	 * FluteDetailView界面中介
	 * @author £iang
	 * 
	 */	
	public class FluteDetailViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** FluteDetailView界面 */
		[Inject]
		public var fluteDetailView:FluteDetailView;
		/** ItemModel */
		[Inject]
		public var itemModel:ItemModel;
		/** weaponModel */
		[Inject]
		public var weaponModel:WeaponModel;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 注册函数 
		 * 
		 */		
		override public function onRegister():void
		{
			addContextListener( FluteDetailViewEvent.SHOW_DETAIL, showDetailHandler );
			addViewListener( ItemEvent.SEARCH_ITEM, searchItemHandler );
			addViewListener( FluteDetailViewEvent.SHOW_MELODY, showMelodyHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理请求显示笛子详细信息时派发的消息 
		 * @param event 请求显示笛子详细信息时派发的消息 
		 * 
		 */		
		protected function showDetailHandler( event:FluteDetailViewEvent ):void
		{
			fluteDetailView.setFluteData( event.weaponVo );
		}
		
		/**
		 * 处理请求查询道具时派发的消息 
		 * @param event 请求查询道具时派发的消息 
		 * 
		 */		
		protected function searchItemHandler( event:ItemEvent ):void
		{
			itemModel.curSearchItemId = event.curSearchItemId;
			dispatch( event );
		}
		
		/**
		 * 处理请求查看旋律表时派发的消息 
		 * @param event 请求查看旋律表时派发的消息 
		 * 
		 */		
		protected function showMelodyHandler( event:FluteDetailViewEvent ):void
		{
			weaponModel.curShowMelodyType = event.melodyType;
			dispatch( event );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeContextListener( FluteDetailViewEvent.SHOW_DETAIL, showDetailHandler );
			removeViewListener( ItemEvent.SEARCH_ITEM, searchItemHandler );
			removeViewListener( FluteDetailViewEvent.SHOW_MELODY, showMelodyHandler );
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function FluteDetailViewMediator()
		{
			super();
		}
	}
}